<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .box{
            width: 400px;
            margin: 100px auto;
            border: 1px solid #ccc;
        }
        #bottom div{
            width: 400px;
            height: 300px;
            background: pink;
            display: none;
        }
        .demo{
            background: #0bf;
        }
    </style>
    <script>
        window.onload = function(){
            var btns = document.getElementsByTagName("button");
            var divs = document.getElementById("bottom").getElementsByTagName("div");
            for(var i=0;i<btns.length;i++)
            {
                btns[i].index = i;  //索引号
                btns[i].onclick = function()
                {
                    for(var j=0;j<btns.length;j++)
                    {
                        btns[j].className = "";
                        divs[j].style.display = "none";
                    }
                    this.className = "demo";
                    divs[this.index].style.display = "block";
                }
            }
        }
    </script>
</head>
<body>
    <div class="box">
        <div class="top">
            <button>第1个</button>
            <button>第2个</button>
            <button>第3个</button>
            <button>第4个</button>
            <button>第5个</button>
        </div>
        <div id="bottom">
            <div>第1个盒子</div>
            <div>第2个盒子</div>
            <div>第3个盒子</div>
            <div>第4个盒子</div>
            <div>第5个盒子</div>
        </div>
    </div>
</body>
</html>